package com.blb.community_admin.service.impl;

import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.community_admin.entity.ZyComplaintSuggest;
import com.blb.community_admin.entity.vo.ComplaintSuggestVO;
import com.blb.community_admin.mapper.ZyComplaintSuggestMapper;
import com.blb.community_admin.service.IZyComplaintSuggestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Service
public class ZyComplaintSuggestServiceImpl extends ServiceImpl<ZyComplaintSuggestMapper, ComplaintSuggestVO> implements IZyComplaintSuggestService {
    @Autowired
    private ZyComplaintSuggestMapper complaintSuggestMapper;

    @Override
    public void downloadExcel(HttpServletResponse response) throws IOException {
        List<ComplaintSuggestVO> suggestVOS= complaintSuggestMapper.selectAllSuggest();
        //设置文件下载
        //设置响应头，告诉浏览器要以文件的形式保存
//        response.setHeader();
        response.setHeader("content-disposition","attachment;filename="+System.currentTimeMillis()+".xlsx");
        //生成Excel并写入
        EasyExcel.write(response.getOutputStream(), ComplaintSuggestVO.class).sheet(System.currentTimeMillis()+"").doWrite(suggestVOS);
    }

    @Override
    public IPage<ComplaintSuggestVO> getSuggestPage(Long current, Long size,ComplaintSuggestVO complaintSuggestVO) {
        return complaintSuggestMapper.selectSuggestPage(new Page<ComplaintSuggestVO>(current,size),complaintSuggestVO);
    }

    @Override
    public List<ComplaintSuggestVO> selectAllSuggest() {
        return complaintSuggestMapper.selectAllSuggest();
    }

    @Override
    public void addSuggest(ComplaintSuggestVO complaintSuggestVO) {
        complaintSuggestMapper.addSuggest(complaintSuggestVO);
    }

    @Override
    public void addOwner(ComplaintSuggestVO complaintSuggestVO) {
        complaintSuggestMapper.addOwner(complaintSuggestVO);
    }
}
